#include <stdlib.h>
#include <stdio.h>

#include "fdtd_aceMesh.h"
#include "slave.h"


extern double ex[NX][NY+1];
extern double ey[NX+1][NY];
extern double hz[NX][NY];
extern double ex1[NX][NY+1]; 
extern double ey1[NX+1][NY]; 
extern double hz1[NX][NY];

#define min(a,b) ((a>b)?(b):(a))
#define max(a,b) ((a>b)?(a):(b))



void stencil_loop1(targs1 *args1)
{
  int j;
  int t_y=args1->t;
  int jj=args1->jj;
  for(j=jj;j<min(NY,jj+TZ2);j++)
        ey[0][j]=t_y;
}
void stencil_loop2(targs2 *args2)
{
  int ii=args2->ii;
  int jj=args2->jj;
  int i,j;
  for(i=max(ii,1);i<min(NX,ii+TZ1);i++)
   for(j=jj;j<min(NY,jj+TZ2);j++)
        ey[i][j] = ey[i][j] - 0.5*(hz[i][j] - hz[i-1][j]);
}
void stencil_loop3(targs2 *args3)
{
  int ii=args3->ii;
  int jj=args3->jj;
  int i,j;
   for (i=ii; i<min(NX,ii+TZ1); i++)
    for(j = max(jj,1); j < min(NY,jj+TZ2); j++)
     ex[i][j] = ex[i][j] - 0.5*(hz[i][j] - hz[i][j-1]);

}

void stencil_loop4(targs2 *args4)
{
  int i,j;
  int ii=args4->ii;
  int jj=args4->jj;
  for(i=ii; i<min(NX,ii+TZ1); i++)
    for(j = jj; j < min(NY,jj+TZ2); j++)
      hz[i][j] = hz[i][j] - 0.7*(ex[i][j+1] - ex[i][j] + ey[i+1][j] - ey[i][j]);
}
